#if defined(USE_FULL_LL_DRIVER)

#include "ll_gpio.h"
#include "ll_exti.h"
#include "stm32f4xx_ll_bus.h"
#include "stdio.h"

#if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || \
    defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK)

// 全局数组，记录每一个引脚的参数
Pin_ST g_pinsGroup[STM32_GPIO_GROUP_MAX*STM32_GPIO_PIN_MAX] = {0};

// 获取LL库需要的GPIOx
GPIO_TypeDef* LL_GET_GPIOX(STM32_GPIO_GROUP group)
{
    GPIO_TypeDef *GroupAddr = NULL;
    switch (group) {
        case STM32_GPIO_GROUP_A:
            GroupAddr = ((GPIO_TypeDef *)GPIOA);
            break;
        case STM32_GPIO_GROUP_B:
            GroupAddr = ((GPIO_TypeDef *)GPIOB);
            break;
        case STM32_GPIO_GROUP_C:
            GroupAddr = ((GPIO_TypeDef *)GPIOC);
            break;
        case STM32_GPIO_GROUP_D:
            GroupAddr = ((GPIO_TypeDef *)GPIOD);
            break;
        case STM32_GPIO_GROUP_E:
            GroupAddr = ((GPIO_TypeDef *)GPIOE);
            break;
        case STM32_GPIO_GROUP_F:
            GroupAddr = ((GPIO_TypeDef *)GPIOF);
            break;
        case STM32_GPIO_GROUP_G:
            GroupAddr = ((GPIO_TypeDef *)GPIOG);
            break;
        case STM32_GPIO_GROUP_H:
            GroupAddr = ((GPIO_TypeDef *)GPIOH);
            break;
        case STM32_GPIO_GROUP_I:
            GroupAddr = ((GPIO_TypeDef *)GPIOI);
            break;
        default:
            break;
    }
    return GroupAddr;
}
// 获取LL库需要的引脚 LL_GPIO_PIN_num
uint32_t LL_GET_HAL_PIN(STM32_GPIO_PIN pin)
{
    return (LL_GPIO_PIN_0 << pin);
}
//  获取LL库需要的时钟
uint32_t LL_GET_GPIO_CLK(STM32_GPIO_GROUP group)
{
    switch (group) {
    case STM32_GPIO_GROUP_A:
        return LL_AHB1_GRP1_PERIPH_GPIOA;
    case STM32_GPIO_GROUP_B:
        return LL_AHB1_GRP1_PERIPH_GPIOB;
    case STM32_GPIO_GROUP_C:
        return LL_AHB1_GRP1_PERIPH_GPIOC;
    case STM32_GPIO_GROUP_D:
        return LL_AHB1_GRP1_PERIPH_GPIOD;
    case STM32_GPIO_GROUP_E:
        return LL_AHB1_GRP1_PERIPH_GPIOE;
    case STM32_GPIO_GROUP_F:
        return LL_AHB1_GRP1_PERIPH_GPIOF;
    case STM32_GPIO_GROUP_G:
        return LL_AHB1_GRP1_PERIPH_GPIOG;
    case STM32_GPIO_GROUP_H:
        return LL_AHB1_GRP1_PERIPH_GPIOH;
    case STM32_GPIO_GROUP_I:
        return LL_AHB1_GRP1_PERIPH_GPIOI;
    default:
        return 0;
    }
}

// 配置GPIO结构体
void LL_CONFIG_GPIO(uint32_t id, uint32_t mode, uint32_t pull, uint32_t speed, uint32_t outType, uint32_t alt)
{
    g_pinsGroup[id].isConfig = 1;
    g_pinsGroup[id].gpioInitStruct.Pin = LL_GET_HAL_PIN(id%16);
    g_pinsGroup[id].gpioInitStruct.Mode = mode;
    g_pinsGroup[id].gpioInitStruct.Pull = pull;
    g_pinsGroup[id].gpioInitStruct.Speed = speed;
    g_pinsGroup[id].gpioInitStruct.OutputType = outType;
    g_pinsGroup[id].gpioInitStruct.Alternate = alt;
}

#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || \
    defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) */

#endif /* USE_FULL_LL_DRIVER */
